package cn.tuling.example;

/**
 * 在《恶魔战士》中，游戏角色“莫莉卡·安斯兰”的原身是一个可爱少女，但当她变身时，会变成头顶及背部延伸出蝙蝠状飞翼的女妖，当然她还可以变为穿着漂亮外衣的少女。
 */
public class DecoratorTest {

    public static void main(String[] args) {
        Morrigan morrigan = new Original();
        morrigan.display();

        System.out.println("--------succubus--------");

        Morrigan succubus = new Succubus(morrigan);
        succubus.display();

        System.out.println("--------gril------------");

        Morrigan girl = new Girl(morrigan);
        girl.display();
    }
}

interface Morrigan {
    void display();
}

class Original implements Morrigan {
    private String image = "origin.jpg";

    public void setImage(String image) {
        this.image = image;
    }

    @Override
    public void display() {
        System.out.println("展示" + image + "形态");
    }
}

abstract class Changer implements Morrigan {
    protected Morrigan morrigan;

    public Changer(Morrigan morrigan) {
        this.morrigan = morrigan;
    }

    abstract void changeImage();
}

class Succubus extends Changer {

    public Succubus(Morrigan morrigan) {
        super(morrigan);
    }

    @Override
    public void display() {
        changeImage();
        morrigan.display();
    }

    @Override
    public void changeImage() {
        ((Original) morrigan).setImage("succubus.jpg");
    }
}

class Girl extends Changer {

    public Girl(Morrigan morrigan) {
        super(morrigan);
    }

    @Override
    void changeImage() {
        ((Original) morrigan).setImage("gril.jpg");
    }

    @Override
    public void display() {
        changeImage();
        morrigan.display();
    }


}